import {
  Entity,
  PrimaryGeneratedColumn,
  CreateDateColumn,
  UpdateDateColumn,
  Column,
  ManyToMany,
  JoinTable,
} from "typeorm";
import { GoodsType } from "./GoodsType.entity";
// 商品
@Entity()
export class Goods {
  @PrimaryGeneratedColumn()
  id: number;

  @Column({
    length: 50,
    comment: "商品名称",
  })
  name: string;

  @Column({
    default: "",
    length: 255,
    comment: "商品简介",
  })
  brief: string;

  @Column({ comment: "商品价格" })
  price: number;

  @Column({ comment: "商品库存" })
  stock: number;

  @Column({ comment: "商品重量" })
  weight: number;

  @Column({ default: 0, comment: "商品推荐指数" })
  recommend: number;

  @Column({
    default: "",
    length: 255,
    comment: "商品标签 ‘,’ 隔开，可多个",
  })
  label: string;

  @Column({ length: 1275, comment: "商品图片 ‘,’ 隔开，可多个" })
  urls: string;

  @Column({
    type: "text",
    comment: "商品详情",
  })
  details: string;

  @Column({
    default: "1",
    length: 2,
    comment: "商品状态 1 生效 2 下架 3 逻辑缺货，具体库存在各自规格",
  })
  status: string;

  @Column({ default: "", comment: "备注" })
  des: string;

  @CreateDateColumn({
    type: "datetime",
    comment: "创建时间",
  })
  create_at: Date;

  @UpdateDateColumn({
    type: "datetime",
    comment: "更新时间",
  })
  update_at: Date;

  @ManyToMany(() => GoodsType, (goodsType) => goodsType.goods)
  @JoinTable()
  goods_types: GoodsType[];
}
